#!/bin/bash

cd `dirname $0`

betaPath=$1
patchPath=$betaPath/patch
binPath=$betaPath/bin
etcPath=$betaPath/etc

chmod -R 777 $patchPath
chmod 777 jq-linux64

launchFile=$etcPath/launch.json
patchConfigFile=$patchPath/patchConfig.json

group=`./jq-linux64 -r .group $launchFile`
exclusions=`./jq-linux64 -r .exclusions $patchConfigFile |   awk BEGIN{RS=EOF}'{gsub(/\n/,",");print}'`

nameplate=$2

url="http://127.0.0.1:30080/login?nextPage=http%3A%2F%2F127.0.0.1%3A30080%2Flaunch2%2Fsystem_module%3Fapp%3D$group%26action%3Dgroupstart%26exclude%3D$exclude&user=admin&password=YiShan@700"

curl -L $url

sleep 3m

url="http://127.0.0.1:30080/launch2/healthcheck/$nameplate"
result=`curl "$url"`
echo $result

i=0
while [ "$result" != "Success" ] && [ $i -lt 6  ]
do
  sleep 3m
  result=`curl "$url"`
  echo $result
  i=$((i=i+1))
done

if [ "$result" == "Success" ]
then
  echo "${nameplate}服务启动成功"
  exit 0
else
  echo "${nameplate}服务启动失败"
  exit 1
fi
